<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
<title>添加教练车</title>
<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.pagination.js"></script>
<script type="text/javascript" src="../../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/public.js"></script>
<script type="text/javascript" src="../../js/validata.js"></script>
<script type="text/javascript" src="../../js/alert.js"></script>
<script type="text/javascript" src="../../js/loadSchoolGrade.js"></script>
<script type="text/javascript" src="../../js/jquery-ui/jquery-ui.min.js"></script>
<!-- WdatePicker -->
<script type="text/javascript" src="../../js/My97DatePicker/WdatePicker.js" ></script>
<link rel="stylesheet" type="text/css" href="../../js/jquery-ui/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.css">
</head>
<body>
	<div class="right_mainH4">
		<p>
			添加教练车 <small>Control panel</small>
		</p>
	</div>
	<div>
		<form id="form1">
			<table class="table table-bordered .table-condensed">
				<tr>
					<td>教练车编号:</td>
					<td></td>
					<td>培训机构:</td>
					<td name="school" id="schools">
					</td> 
					<td rowspan="8" id="simg">
						<div class="userface" id="touxiang" onclick="uploadTouxiang();"><span>上传教练车照片</span></div>
						<input type="hidden" name="photoImg" />
					</td>
				</tr>
				<tr>
					<td>教练车品牌:</td>
					<td>
						<input type="text" name="brand" class="required maxlength:20" />
					</td>
					<td>车牌号:</td>
					<td>
						<input type="text" name="licnum" class="required carNum"/>
					</td>
				</tr>
				<tr>
					<td>教练车型号:</td>
					<td>
						<input type="text" name="model" class="required maxlength:20"/>						 
					</td>
					<td>培训车型:</td>
					<td >
						<select name="perdritype" id="perdritype" style="width: 90px;">
							<option value="A1">A1</option>
							<option value="A2">A2</option>
							<option value="A3">A3</option>
							<option value="B1">B1</option>
							<option value="B2">B2</option>
							<option value="C1">C1</option>
							<option value="C2">C2</option>
							<option value="C3">C3</option>
							<option value="C4">C4</option>
							<option value="C5">C5</option>
							<option value="D">D</option>
							<option value="E">E</option>
							<option value="F">F</option>
							<option value="M">M</option>
							<option value="N">N</option>
							<option value="P">P</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>教练车年限:</td>
					<td>
						<input type="text" name="carYear" class="required onlyNum"/>
					</td>
					<td>载客量:</td>
					<td>
						<input type="text" name="carLoad" class="required onlyNum"/>
					</td>
				</tr>
				<tr>
					<td>车牌颜色:</td>
					<td>
						<select name="platecolor" id="platecolor" style="width: 90px;">
							<option value="2">黄色</option>
							<option value="1">蓝色</option>
							<option value="3">黑色</option>
							<option value="4">白色</option>
							<option value="5">绿色</option>
							<option value="9">其他</option>
						</select>
					</td>
					<td>准教科目:</td>
					<td>
						<label><input type="checkbox" id="keMu1" value="2" />科目二</label>
						<label><input type="checkbox" id="keMu2" value="3"  />科目三</label>
						<input type="hidden" name="keMu"  class="required"/>
					</td>
				</tr>
				<tr>
					<td>生产厂家:</td>
					<td>
						<input type="text" name="manufacture" class="required maxlength:20"/>
					</td>
					<td>发动机号:</td>
					<td>
						<input type="text" name="engnum" class="required maxlength:32"/>
					</td>
				</tr>
				<tr>
					<td>车架号:</td>
					<td>
						<input type="text" name="franum" class="required maxlength:32"/>
					</td>
					<td>购买日期:</td>
					<td>
						<input type="text" name="buydate" onClick="WdatePicker();"  class="required date"/>
					</td>
				</tr>
				<tr>
					<td>教练车管理员:</td>
					<td>
						<input type="text" id="driver" readonly="readonly"/>
						<button type="button" onclick="bindDriver();" class="btn btn-danger">绑定管理员</button>
					</td>
				</tr>
				<tr>
					<td colspan="5" style="text-align: center;">
						<button type="button" onclick="addCar();" class="btn btn-info">添加</button>
					</td>
				</tr>
			</table>
		</form>
	</div>
	
     <!-- 上传教练车照片 -->
     <div id="uploadImgDiv" style="display:none;" title="图片上传">
     	<iframe src="" style="width:100%;height: 100%" frameborder="no" marginwidth="0" marginheight="0" allowtransparency="yes"></iframe>
     </div>
     
     <!-- 绑定管理员 -->
	<div id="bindDriverDiv" style="display:none;" title="绑定管理员">
		<iframe src="" style="width:100%;height: 100%" frameborder="no" marginwidth="0" marginheight="0" allowtransparency="yes"></iframe>
	</div>
    <script type="text/javascript">
    	var driverId = "";
		$(function(){
			var storage = window.sessionStorage;
		    var schools = storage.getItem("schools");//获取存在sessionStorage里的驾校数据
		    if(schools != null){
		    	var schoolHtml;
		    	schoolHtml = '<select name="addCoachCar.school" class="required" id="school" style="width: 160px;">';
		    	schoolHtml += schools;
		    	schoolHtml += '</select>';
		    	$("#schools").html(schoolHtml);
		    }
		});
		
    	//添加教练车信息
    	function addCar(){
    		var keMu="";
    		$("#form1").find("input[id^='keMu']").each(function(){
    			var check = $(this).prop("checked");
    			if(check == true){
    				keMu += $(this).val()+",";
    			}
    		});
    		keMu = keMu.substr(0,keMu.length-1);
			$("input[name='keMu']").val(keMu);
    		
    		var photoImg = $("input[name='photoImg']").val();
			if(!isNull(photoImg)){
    			sAlert("请上传照片!");	
    			return;
    		}
			if(validata("form1")){
	    		$.ajax({
	    			url : "../../coachCar/add.ao?driverId="+driverId,
	    			type : 'POST',
	    			data :$("#form1").serialize(),
	    			cache : false,
	    			beforeSend : ajaxstar,
	    			complete : ajaxend,
	    			dataType : "json",
	    			success : function(data) {
						sAlert(data["result"]);
	    				if(data["state"] == "success"){
	    					clearTable("form1");
	    				}
	    			}
	    		});
			}
    	}
    	
    	//上传教练车图片
    	function uploadTouxiang(){
			$("#uploadImgDiv").find("iframe").attr("src","../upload/touxiangUpload.html?case=1&f=2");
			$("#uploadImgDiv").dialog({
				title : "上传图片",
				resizable : false,
				width : 850,
				height : 600,
				resizable : true,
				modal : true,
				buttons : {
					"关闭" : function() {
						$(this).dialog("close");
					}
				}
			});
    	}

    	function setImg(path){
    		$("#uploadImgDiv").dialog("close");
    		$("input[name='photoImg']").val(path);
    		$("div[class='userface']").html("<img src='" + pickerProjectAdd + path + "' />");
    	}
    	
    	//为教练车绑定教练员
		function bindDriver(){
    		var schoolId = $("#school").val();
    		if(!isNull(schoolId)){
    			sAlert("请选择培训机构!");	
    			return;
    		}else{
				$("#bindDriverDiv").find("iframe").attr("src","bindDriver.html?id="+schoolId);
				$("#bindDriverDiv").dialog({
					title : "绑定管理员",
					resizable : false,
					width : 850,
					height : 700,
					resizable : true,
					modal : true,
					buttons : {
						"关闭" : function() {
							$(this).dialog("close");
						}
					}
				});
    		}
		}

    	function setCarManage(id,name){
    		driverId = id.replace(/\s+/g,"");//去除字符串中所有的空格
    		$("#driver").val(name);
    	}
    </script>
</body>
</html>